package cn.net.yato.picture.biz.impl;

import cn.net.yato.picture.biz.UserBiz;
import cn.net.yato.picture.entity.User;
import cn.net.yato.picture.mapper.UserMapper;
import cn.net.yato.picture.util.TransactionalUtil;
import cn.net.yato.picture.util.log.MyPointcut;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName UserBizImpl
 * @Description TODO
 * @Author yato
 * @Date 2020/2/19 14:57
 * @Version 1.0
 */
@Service
public class UserBizImpl implements UserBiz {

    @Resource
    private UserMapper userMapper;

    @MyPointcut
    @Override
    public List<User> getAllUsersBiz() {
        return userMapper.getAllUsers();
    }

    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
    @MyPointcut
    @Override
    public int modifyLastLoginDateBiz(User user) {
        int temp = userMapper.updateById(user);
        if (temp == 0){
            TransactionalUtil.rollback();
        }
        return temp;
    }


}
